package cn.broadsense.biz.dto;

import cn.broadsense.biz.domain.ItemTag;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 事件模板DTO
 *
 * @author: pengxin
 * @create: 2024-09-18 10:58
 * @Version 1.0
 **/
@ApiModel(value = "事件模板")
@Data
public class ItemTagTemplateDto implements Serializable {

    private static final long serialVersionUID = 8592917913722724144L;


    @ApiModelProperty(value = "主键ID")
    private Long id;

    @ApiModelProperty(value = "模板名称")
    private String templateName;

    @ApiModelProperty(value = "模板说明")
    private String templateSpecification;

    @ApiModelProperty(value = "必填标签数量")
    private Integer requiredQty;

    @ApiModelProperty(value = "标签数量")
    private Integer totalQty;

    @ApiModelProperty(value = "已填写标签数量")
    private Integer filledQty;

    @ApiModelProperty(value = "标签列表")
    private List<ItemTag> itemTagList;

    public Integer getFilledQty() {
        if (itemTagList != null && !itemTagList.isEmpty()) {
            return Math.toIntExact(itemTagList.stream().filter(itemTag -> itemTag.getFieldValue() != null).count());
        } else {
            return 0;
        }
    }
}
